package com.wwzh.interview.study.thread;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;

class MyThread1 implements Runnable{

    @Override
    public void run() {

    }
}

class MyThread2 implements Callable<Integer>{

    @Override
    public Integer call() throws Exception {
        System.out.println(Thread.currentThread().getName() + "********************come in callable");
        try {
            TimeUnit.SECONDS.sleep(3);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return 1024;
    }
}

public class CallableDemo {
    public static void main(String[] args) throws Exception {
        FutureTask<Integer> task = new FutureTask<>(new MyThread2());
        FutureTask<Integer> task2 = new FutureTask<>(new MyThread2());

        new Thread(task,"AA").start();
        new Thread(task2,"BB").start();
        System.out.println(Thread.currentThread().getName()+"************");
        int result = 100;

        int result02 = task.get();  //获取callable线程的结果
        System.out.println("*********result " + (result+ result02));

    }
}
